/**
 * Copyright (C) 2013 DaiKit.com - daikit4gxt-sample module (admin@daikit.com)
 *
 *         Project home : http://code.daikit.com/commons
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.daikit.daikit4gxtsample.client.screen.testscreen.producteditor;

import com.daikit.daikit4gxt.client.action.DkBaseAction;
import com.daikit.daikit4gxt.client.ui.forms.DkFixedFormPanel;
import com.daikit.daikit4gxtsample.client.Main;
import com.daikit.daikit4gxtsample.client.screen.testscreen.TestScreen;
import com.sencha.gxt.widget.core.client.TabItemConfig;
import com.sencha.gxt.widget.core.client.form.FieldLabel;


/**
 * Third tab of {@link TestScreen} editor
 * 
 * @author tcaselli
 * @version $Revision$ Last modifier: $Author$ Last commit: $Date$
 */
public class ProductEditorTab3 extends AbstractEditorTab
{

	private final FieldLabel verySpecialPropertyFieldLabel;

	/**
	 * Constructor
	 * 
	 * @param controller
	 */
	public ProductEditorTab3(final ProductEditorController controller)
	{
		super(controller);
		final TabItemConfig tabItemConfig = new TabItemConfig();
		tabItemConfig.setIcon(Main.icons().table_16());
		tabItemConfig.setText(Main.gwtSampleI18n().test_screen_editor_tab_3_title());
		setTabItemConfig(tabItemConfig);

		final FieldLabel property3FieldLabel = new FieldLabel(getEditor().property3, Main.gwtSampleI18n().product_property3());
		final FieldLabel property4FieldLabel = new FieldLabel(getEditor().property4, Main.gwtSampleI18n().product_property4());
		final FieldLabel propertyBooleanFieldLabel = new FieldLabel(getEditor().propertyBoolean, Main.gwtSampleI18n()
				.product_propertyBoolean());
		verySpecialPropertyFieldLabel = new FieldLabel(getEditor().productVerySpecialSubTypeEditor.getEditor().verySpecial, Main
				.gwtSampleI18n().product_very_special_property());

		final DkFixedFormPanel myFormPanel = new DkFixedFormPanel(2);

		myFormPanel.add(property3FieldLabel, 0);
		myFormPanel.add(property4FieldLabel, 1);
		myFormPanel.add(propertyBooleanFieldLabel, 0);
		myFormPanel.add(verySpecialPropertyFieldLabel, 0);

		add(myFormPanel);
	}

	@Override
	public void invalidateUi()
	{
		getTabItemConfig().setEnabled(getEditor().isEditing());
		getEditor().property3.setEnabled(getEditor().isEditing());
		getEditor().property4.setEnabled(getEditor().isEditing());
		getEditor().propertyBoolean.setEnabled(getEditor().isEditing());
		getEditor().productVerySpecialSubTypeEditor.getEditor().verySpecial.setEnabled(getEditor().isEditing());

		final boolean isVerySpecialProductData = getEditor().isVerySpecialProductData();
		verySpecialPropertyFieldLabel.setVisible(isVerySpecialProductData);
	}

	@Override
	public boolean needToBeReloaded()
	{
		return true;
	}

	@Override
	public DkBaseAction<?> getReloadSubPanelAction(final boolean force, final Object... optionalArgs)
	{
		return null;
	}

}
